<template>
    <div class="list" ref='listWrapper'>
        <div>
      <div class="area">
          <div class="map-title borde-tb">当前城市</div>
          <router-link to='/'>
          <div class="button-List">
              <div class="cityButton">
                  <div class="button new">{{this.$store.state.city}}</div>
              </div>
          </div>
          </router-link>
          </div>
      <div class="area">
          <div class="map-title borde-tb">热门城市</div>
          <div class="button-List">
              <div @click="handleClick(item.name)" class="cityButton" v-for="item of hotCities" :key='item.id'>
                  <div class="button">{{item.name}}</div>
              </div>
          </div>
          </div>
          <div class="area" v-for="(item, key) of cities" :key='key' :Acity='item' :ref='key'>
          <div class="map-title borde-tb">{{key}}</div>
          <div class="button-List">
              <div @click="handleClick(cityItem.name)" class="cityButton" v-for="cityItem of item" :key="cityItem.id">
                  <div class="button">{{cityItem.name}}</div>
              </div>
          </div>
          </div>
    </div>
    </div>
</template>

<script>
import BScroll from 'better-scroll'
export default {
  name: 'List',
  data () {
    return {
      itemLetter: ''
    }
  },
  props: {
    hotCities: Array,
    cities: Object,
    letter: String
  },
  methods: {
    handleClick (city) {
      this.$store.dispatch('changeCity', city)
      this.$router.push('/')
    }
  },
  mounted () {
    this.scroll = new BScroll(this.$refs.listWrapper, { mouseWheel: true, click: true, tap: true })
  },
  watch: {
    letter () {
      if (this.letter) {
        this.scroll.scrollToElement(this.$refs[this.letter][0])
      }
    }
  }
}
</script>

<style lang="stylus" scoped>
@import '~style/varibles.styl'
.list
  overflow hidden
  position absolute
  top 1.58rem
  bottom 0
  left 0
  right 0
  .map-title
    line-height .6rem
    text-indent .2rem
    background #eee
    color #666
  .new
    color $bgColor
    border-color $bgColor!important
  .button-List
    padding .1rem .4rem
    overflow hidden
    .cityButton
      color #666
      float left
      width 33.33%
      .button
        padding .1rem
        margin .1rem
        border .02rem solid #ccc
        border-radius .06rem
        text-align center
</style>
